From d3b9fcdc4a9041ca0a8c6e01a3f639caa96aa376 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Tue, 4 Jan 2011 04:20:09 +0000 Subject: [PATCH] Followup r79520 and r79528, one of the args was missing when calling doEditSectionLink. Additionally the LanguageConverter was screwing up editsection markers really badly. Switched to pesudo-xml style markers for best compatibility with the language converter. (tags are already escaped so we don't need to worry about similar user input) --- includes/parser/Parser.php | 20 +++++++++++++++----- includes/parser/ParserOutput.php | 11 +++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 37f5149c8a..568d7449d8 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3699,7 +3699,7 @@ class Parser { if ( $showEditLink ) { $editLinkAsToken = $this->mOptions->getEditSectionTokens(); if ( $editLinkAsToken ) { - $this->mOutput->setEditSectionTokens( "{$this->mUniqPrefix}-editsection-", self::MARKER_SUFFIX ); + $this->mOutput->setEditSectionTokens( true ); } } @@ -3964,10 +3964,20 @@ class Parser { } else { $editlinkArgs = array( $this->mTitle->getPrefixedText(), $sectionIndex, $headlineHint ); } - // We use nearly the same structure as uniqPrefix and the marker stuffix (besides there being nothing random) - // However the this is output into the parser output itself not replaced early, so we hardcode this in case - // the constants change in a different version of MediaWiki, which would break this code. - $editlink = "{$this->mUniqPrefix}-editsection-" . implode('|', array_map('urlencode', $editlinkArgs)) . self::MARKER_SUFFIX; + // We use a bit of pesudo-xml for editsection markers. The language converter is run later on + // Using a UNIQ style marker leads to the converter screwing up the tokens when it converts stuff + // And trying to insert strip tags fails too. At this point all real inputted tags have already been escaped + // so we don't have to worry about a user trying to input one of these markers directly. + // We use a page and section attribute to stop the language converter from converting these important bits + // of data, but put the headline hint inside a content block because the language converter is supposed to + // be able to convert that piece of data. + $editlink = ''; + } else { + $editlink .= '/>'; + } } else { // Output edit section links directly as markup like we used to if ( $isTemplate ) { diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 32153e653a..0ad7845202 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -137,8 +137,7 @@ class ParserOutput extends CacheTime { function getText() { if ( $this->mEditSectionTokens ) { - $editSectionTokens = $this->mEditSectionTokens; - return preg_replace_callback( "#{$editSectionTokens[0]}(.*?){$editSectionTokens[1]}#", array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); + return preg_replace_callback( '#|>(.*?)())#', array( &$this, 'replaceEditSectionLinksCallback' ), $this->mText ); } return $this->mText; } @@ -149,7 +148,11 @@ class ParserOutput extends CacheTime { */ function replaceEditSectionLinksCallback( $m ) { global $wgUser, $wgLang; - $args = array_map('urldecode', explode('|', $m[1], 3)); + $args = array( + htmlspecialchars_decode($m[1]), + htmlspecialchars_decode($m[2]), + $m[4] ? $m[3] : null, + ); $args[0] = Title::newFromText( $args[0] ); if ( !is_object($args[0]) ) { throw new MWException("Bad parser output text."); @@ -184,7 +187,7 @@ class ParserOutput extends CacheTime { function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); } function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); } - function setEditSectionTokens( $p, $s ) { return wfSetVar( $this->mEditSectionTokens, array( $p, $s ) ); } + function setEditSectionTokens( $t ) { return wfSetVar( $this->mEditSectionTokens, $t ); } function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); } function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); } -- 2.20.1